﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cosmetic.Logic;
using System.Data;
using Cosmetic.DataEntity;
using Cosmetic;

namespace WebApp.Space.AccountInfo
{
    public partial class MemberAddress : PageBase
    {
        PurchaseManager m_PurchaseManager = new PurchaseManager();
        UserManager m_UserManager = new UserManager();
        //UserInfo userinfo;
        AddressManager addressmanger = new AddressManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.SignInUser == null)
            {
                Page.RegisterClientScriptBlock("key", "<script>window.top.location = '/Login.aspx';</script>");
                return;
            }
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            DataSet ds = AddressManager.SelectByUserId(this.SignInUser.UserId.ToString());
            //this.LinkButton1.CommandArgument = ds.Tables[0].Rows[0]["AddressId"].ToString();
            if (ds.Tables[0].Rows.Count > 0)
            {
                string ReceiverName = ds.Tables[0].Rows[0]["name"].ToString();
                string Address = ds.Tables[0].Rows[0]["Address"].ToString();
                string Phone = ds.Tables[0].Rows[0]["Mobile"].ToString();
                if (!string.IsNullOrEmpty(ReceiverName))
                {
                    this.ltlReceiverName.Text = ReceiverName;//收货人。
                }
                if (!string.IsNullOrEmpty(Address))
                {
                    this.ltlAddress.Text = Address;//地    址
                }
                if (!string.IsNullOrEmpty(Phone))
                {
                    this.ltlPhone.Text = Phone;
                }

                //this.txtReceiverName.Text = ds.Tables[0].Rows[0]["name"].ToString();//收货人。
                //this.txtAddress.Text = ds.Tables[0].Rows[0]["Address"].ToString();//地    址
                //this.txtPhone.Text = ds.Tables[0].Rows[0]["Mobile"].ToString();
                hfAddressId.Value = ds.Tables[0].Rows[0]["AddressId"].ToString();
            }


        }

        //protected void LinkButton1_Click(object sender, EventArgs e)
        //{
        //    this.ltlReceiverName.Visible = false;
        //    this.ltlPhone.Visible = false;
        //    this.ltlAddress.Visible = false;

        //    this.txtAddress.Visible = true;
        //    this.txtPhone.Visible = true;
        //    this.txtReceiverName.Visible = true;
        //    this.LinkButton1.Visible = false;
        //    this.ImageButton1.Visible = true;
        //}

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {//提交
            //if (string.IsNullOrEmpty(hfAddressId.Value))
            //{
            //    Address address = new Address();
            //    address.Mark = true;
            //    address.AddressId = new Guid();
            //    //theaddress.Consignee = this.DropDownList1.SelectedItem.Text + this.DropDownList2.SelectedItem.Text + this.DropDownList3.SelectedItem.Text;
            //    address.UserId = this.SignInUser.UserId;

            //    address.Mobile = this.txtPhone.Text;
            //    address.Address1 = this.txtAddress.Text;
            //    address.name = this.txtReceiverName.Text;

            //    addressmanger.Insert(address);
            //    WebGeneric.WebMessageBox("添加成功!", this.Page);
            //    //this.HiddenField1.Value = "1";//为0表示是”修改“。
            //    Bind();
            //}
            //else
            //{
            //    Address theaddress = addressmanger.GetAddressById(new Guid(hfAddressId.Value));
            //    theaddress.Mark = true;
            //    //theaddress.Consignee = this.DropDownList1.SelectedItem.Text + this.DropDownList2.SelectedItem.Text + this.DropDownList3.SelectedItem.Text;
            //    theaddress.UserId = new Guid(Session["userid"].ToString());

            //    //theaddress.Mobile = this.txtPhone.Text;
            //    //theaddress.Address1 = this.txtAddress.Text;
            //    //theaddress.name = this.txtReceiverName.Text;

            //    addressmanger.Update();
            //    WebGeneric.WebMessageBox("修改成功!", this.Page);
            //    //this.HiddenField1.Value = "1";//为0表示是”修改“。
            //    Bind();
            //}

            //this.ltlReceiverName.Visible = true;
            //this.ltlPhone.Visible = true;
            //this.ltlAddress.Visible = true;

            //this.txtAddress.Visible = false;
            //this.txtPhone.Visible = false;
            //this.txtReceiverName.Visible = false;

            //this.LinkButton1.Visible = true;
            //this.ImageButton1.Visible = false;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Space/AccountInfo/MemberAddressEdit.aspx?AddressId="+ this.hfAddressId.Value);
        }
    }
}